package com.example.rabbitmqstudy.queue;

import com.example.rabbitmqstudy.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class SendMessage {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(QueueData.QUEUE_NAME, false, false, false, null);

        for (int index = 0; index < 10; index++) {
            String message = String.format("hello, rabbit: %d", index);
            channel.basicPublish("", QueueData.QUEUE_NAME, null, message.getBytes());
        }

        channel.close();
        connection.close();
    }
}
